using System.IO;
using SolutionFactory.Services;

namespace SolutionFactory_console
{
	public class RenameSolutionFileVisitor : IFileVisitor
	{
		private readonly IFileSystem _fileSystem;
		private readonly string _sourceName;
		private readonly string _destinationName;

		public RenameSolutionFileVisitor(IFileSystem fileSystem,string sourceName, string destinationName)
		{
			_fileSystem = fileSystem;
			_sourceName = sourceName;
			_destinationName = destinationName;
		}

		public void Visit(FileInfo file)
		{
			if(file.Exists&& _fileSystem.GetFileName(file.Name).Contains(_sourceName))
			{
				file.MoveTo(file.DirectoryName.Combine( file.Name.Replace(_sourceName,_destinationName)));
			}
		}
	}
}